﻿<%@ Register TagPrefix="cnt" Namespace="Mysoft.Map.Application.Controls" Assembly="Mysoft.Map.Application.Components" %>
<%@ Register TagPrefix="mnu" Namespace="Mysoft.Map.Application.Menus" Assembly="Mysoft.Map.Application.Components" %>
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="Zkgl_Zkfa_Edit.aspx.vb" Inherits="Slxt.Zkgl_Zkfa_Edit" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
	<HEAD>
		<title>折扣方案信息</title>
	    <!-- Global -->
	    <link rel="stylesheet" type="text/css" href="/_common/styles/global.css" />
	    <script type="text/javascript" src="/_common/scripts/global.js"></script>
	    <!-- Menu -->
	    <link rel="stylesheet" type="text/css" href="/_nav/menu.css" />
	    <script type="text/javascript" src="/_nav/menu.js"></script>
	    <!-- Form -->
	    <link rel="stylesheet" type="text/css" href="/_forms/styles/form.css" />
	    <script type="text/javascript" src="/_forms/FormBase.js"></script>
	    <!-- Datetime & Number -->
	    <script type="text/javascript" src="/_controls/settings.aspx"></script>
	    <script type="text/javascript" src="/_controls/datetime/date.js"></script>
	    <script type="text/javascript" src="/_controls/datetime/time.js"></script>
	    <script type="text/javascript" src="/_controls/number/number.js"></script>
	    <!-- Select -->
	    <link rel="stylesheet" type="text/css" href="/_common/styles/select.css" />
	    <!-- Lookup -->
	    <script type="text/javascript" src="/_controls/lookup/map_lookup.js"></script>
	    <script type="text/javascript" src="/_controls/lookup/map_lookupDialogs.js"></script>
	    <script type="text/javascript" src="/_controls/lookup/selectteamuser.js"></script>
	    <!-- Navbar -->
	    <link rel="stylesheet" type="text/css" href="/_nav/nav.css" />
	    <script type="text/javascript" src="/_common/scripts/Details.js"></script>
	    <!-- Tab -->
	    <link rel="stylesheet" type="text/css" href="/_nav/tabs.css" />
	    <!-- Utility-->
	    <script type="text/javascript" src="/_controls/util/util.js"></script>
		<script language="javascript" src="/Slxt/js/Public.js"></script>
		<script language="javascript">

		    function win_load() {
		        //控制价格试算按钮是否可用
		        if (document.all("txtBtnPrice").value == "1") {
		            document.all("btnTestPrice").disabled = false;
		        }
		    
		        //界面初始化
		        if (__mode.value == "1") {
		            //新增
		            document.getElementById("appIframeZkItem").src = "/Slxt/XTCS/Zkgl_ZkItem_Grid.aspx?oid=" + appForm.oid.value + "&projguid=" + escape(__projguid.value) + "&funcid=01010107&mode=1";
		        }
		        else {
		            //修改
		            //加载折扣明细列表
		            document.getElementById("appIframeZkItem").src = "/Slxt/XTCS/Zkgl_ZkItem_Grid.aspx?oid=" + __oid.value + "&projguid=" + escape(__projguid.value) + "&funcid=01010107&mode=2";
		        }
		    }



		    var isEnable = false;		    
		    //保存前校验
		    function Valid() {
		        //当前项目下折扣方案名称是否同名
		        var sDiscntPlanName = appForm.DiscntPlanName.value;
		        var sFile = "/Slxt/XTCS/Zkgl_XMLHTTP.aspx?ProjGUID=" + escape(appForm.ProjGUID.value) + "&oid=" + escape(appForm.oid.value);
		        var sRtn = openXMLHTTP(sFile, "chkDiscntPlanRepeat",sDiscntPlanName);
		        if (sRtn == "重复") {
		            alert("当前项目下折扣方案名称重复，请重新输入！");
		            appForm.DiscntPlanName.focus();
		            return false;
		        }

		        //校验是否有折扣项，没有则不能保存
		        var iRow = document.getElementById("appIframeZkItem").contentWindow.document.getElementById("gridBar").childNodes.item(0).rows.length;
		        if (iRow < 3) {
		            alert("当前折扣方案只包含付款方式折扣，请录入折扣项！");
		            return false;
		        }
		        
		        //校验当前项目下是否有已经启用的折扣方案
		        if (appForm.IsEnabled.value == "1") {
		            var sFile = "/Slxt/XTCS/Zkgl_XMLHTTP.aspx?ProjGUID=" + escape(appForm.ProjGUID.value) + "&oid=" + escape(appForm.oid.value);
		            var sRtn = openXMLHTTP(sFile, "CheckIsEnabled");
		            if (sRtn == "Yes") {
		                if (confirm("项目下存在启用的折扣方案，是否禁用原方案，启动当前方案?")) {
		                    isEnable = true;
		                    return true;
		                }
		                else {
		                    return false;
		                }
		            }
		            else {
		                return true;
		            }
		        }

		    }

		    function oprBeforeSave() {


		        if (Valid() == false ) {
		            event.returnValue = false;
		            return false;
		        }
		        else {
		                var ModifyOn = document.getElementById("txtNowDate").value;
		                var ModifyBy = document.getElementById("txtUserName").value;
		                appForm.ModifyOn.setValue(ModifyOn);
		                appForm.ModifyBy.setValue(ModifyBy);
		                
	                    var sUserDataXml = "";
	                    sUserDataXml = appIframeZkItem.getSaveXml();
	                    appForm.userxml = sUserDataXml;
	                    appForm.BuildXml();
		                return true;
		        }
		    }

		    function oprAfterSave() {
		        var xmlDom = new ActiveXObject("Microsoft.XMLDOM");
		        var oid;
		        xmlDom.loadXML(appForm.returnxml);
		        if (xmlDom.documentElement.attributes.getNamedItem("result").value == "true") {
		            oid = xmlDom.documentElement.attributes.getNamedItem("keyvalue").value;
		            //保存前当前项目下已有启用的折扣方案，再保存一条要启用的折扣方案时，则禁用原启用方案，启用该方案
		            if (isEnable) {
		                var strGUID = appForm.ProjGUID.value + "|" + oid;
		                var sFile = "/Slxt/XTCS/Zkgl_XMLHTTP.aspx";
		                var sRtn = openXMLHTTP(sFile, "EnabledOperate", strGUID);
		                if (sRtn != "success") {
		                    alert(sRtn);
		                    return
		                }
		            }
		            appIframeZkItem.location.href = appIframeZkItem.location.href;
		        }
		    }

		    //功能：价格试算
		    function toTestPrice() {
		        var sPath = "/Slxt/XTCS/Zkgl_TestPrice.aspx";
		        var sParams = "mode=1";
		        sParams += "&ProjGUID=" + escape(appForm.ProjGUID.value);
		        var iX = 720;
		        var iY = 340;
		        var strReturn = openMyDlg("价格试算", sPath, sParams, window, iX, iY);
		    }
            
		</script>
	</HEAD>
	<body MS_POSITIONING="GridLayout" onload="win_load();">
		<TABLE id="Table1" height="100%" cellSpacing="0" cellPadding="0" width="100%" border="0">
			<tr height="48">
				<td><mnu:appformmenu id="appFormMenu" runat="server"></mnu:appformmenu></td>
			</tr>
			<tr>
				<td>
					<div class="area">
						<cnt:appform id="appForm" runat="server" processtype="xmlhttp" onBeforeSave="oprBeforeSave()" onaftersave="oprAfterSave()"></cnt:appform>
					</div>
				</td>
			</tr>
			<tr>
				<td class="statusBar" colSpan="2"><b></b></td>
			</tr>
		</TABLE>
		<form id="Form1" runat="server">
			<asp:textbox id="txtJsfs" style="DISPLAY: none" Runat="server"></asp:textbox>
			<asp:textbox id="txtNowDate" style="DISPLAY: none" Runat="server"></asp:textbox>
			<asp:textbox id="txtUserName" style="DISPLAY: none" Runat="server"></asp:textbox>
			<asp:textbox id="txtBtnPrice" style="DISPLAY: none" Runat="server"></asp:textbox>
		</form>
	</body>
</HTML>
